#!/bin/bash
CURRENT_PATH=$(pwd);
ROOT_PATH=$(cd `dirname $0`/; pwd);
cd $CURRENT_PATH;

sudo cp $ROOT_PATH/apt_erlang /etc/apt/preferences.d/erlang
sudo apt-cache policy
echo "deb https://dl.bintray.com/rabbitmq/debian xenial main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list
wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -
sudo apt-get update
wget http://packages.erlang-solutions.com/site/esl/esl-erlang/FLAVOUR_1_general/esl-erlang_20.3-1~ubuntu~xenial_amd64.deb
sudo dpkg -i esl-erlang_20.3-1~ubuntu~xenial_amd64.deb
sudo apt-get install erlang-nox
sudo apt-get install rabbitmq-server
sudo rabbitmq-plugins enable rabbitmq_management
sudo rabbitmq-plugins enable rabbitmq_mqtt
rabbitmqctl add_user robot-server robot-server
rabbitmqctl set_permissions -p / robot-server ".*" ".*" ".*"
rabbitmqctl set_user_tags robot-server management